package visual;
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class GameFrame extends JFrame implements ActionListener{
/*
 * Atributes
 */
	String MENU_STRINGS[] = {
			"Juego"
		};
	Object ITEM_STRINGS[] = {
			"Juego Nuevo",
			"Salvar Juego",
			"Cargar Juego",
			"Salir"
		};
		
/*
 * Constructors
 */
	public GameFrame(String windowName) throws HeadlessException {
		super(windowName);
		getContentPane().setLayout(new FlowLayout ());
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		create_menu();
		setSize(new Dimension(800, 600));
        setLocationRelativeTo(null);
	}

/*
 * Methods
 */
	public void close(){
		setVisible(false);
		dispose();
	}
	
	public void createAndShowGUI() {
        setLocationRelativeTo(null);
        setVisible(true);
	}
	
	private void create_menu(){
		JMenuBar menuBar;
		JMenu gameMenu;
		JMenuItem menuItem;
		menuBar = new JMenuBar();
		gameMenu = new JMenu(MENU_STRINGS[0]);
		gameMenu.setMnemonic(KeyEvent.VK_J);
		for(int i = 0; i < ITEM_STRINGS.length; i++){
			menuItem = new JMenuItem(ITEM_STRINGS[i].toString());
			if(i == ITEM_STRINGS.length - 1){
				gameMenu.addSeparator();
			}
			menuItem.addActionListener(this);
			gameMenu.add(menuItem);

		}
		JLabel label = new JLabel("Hola");
		menuBar.add(gameMenu);
		setJMenuBar(menuBar);
	}

	public void actionPerformed(ActionEvent event) {
		if(event.getActionCommand() == ITEM_STRINGS[0]){
			create_new_game();
		}else if(event.getActionCommand() == ITEM_STRINGS[3]){
			close();
		}
		//System.out.println("event: " + event);
	}
	
	public void create_new_game(){
		JInternalFrame newGameFrame = new JInternalFrame("New Game");
		newGameFrame.getContentPane().add(new JButton("One"));
		newGameFrame.setVisible(true);
		getContentPane().add(newGameFrame);
	}
}
